# Maintainer: Diego Sogari <diego.sogari@gmail.com>

_realname=fann
pkgbase=mingw-w64-${_realname}
pkgname="${MINGW_PACKAGE_PREFIX}-${_realname}"
pkgver=2.2.0
pkgrel=3
pkgdesc="Fast Artificial Neural Network Library (mingw-w64)"
arch=('any')
mingw_arch=('mingw64' 'ucrt64' 'clang64' 'clangarm64')
url="https://leenissen.dk/fann/"
msys2_repository_url="https://github.com/libfann/fann"
license=('spdx:LGPL-2.1-or-later')
makedepends=("${MINGW_PACKAGE_PREFIX}-cc" "${MINGW_PACKAGE_PREFIX}-cmake")
source=("https://github.com/libfann/fann/archive/${pkgver}/${_realname}-${pkgver}.tar.gz"
        "fann-2.2.0.patch")
sha256sums=('f31c92c1589996f97d855939b37293478ac03d24b4e1c08ff21e0bd093449c3c'
            '487aa5ac2201abb8824d1b3b31c7ec1cfd75024982edfe88bca198835912b5c6')

prepare() {
  cd "${srcdir}/${_realname}-${pkgver}"
  patch -Np1 -i "../${_realname}-${pkgver}.patch"
}

build() {
  rm -rf "${srcdir}/build-${MSYSTEM}"
  mkdir "${srcdir}/build-${MSYSTEM}"
  cd "${srcdir}/build-${MSYSTEM}"

  MSYS2_ARG_CONV_EXCL="-DCMAKE_INSTALL_PREFIX=" \
  ${MINGW_PREFIX}/bin/cmake.exe \
    -G"MSYS Makefiles" \
    -DCMAKE_INSTALL_PREFIX=${MINGW_PREFIX} \
    "../${_realname}-${pkgver}"

  ${MINGW_PREFIX}/bin/cmake --build .
}

package() {
  cd "${srcdir}/build-${MSYSTEM}"
  DESTDIR="${pkgdir}" ${MINGW_PREFIX}/bin/cmake --install .
  
  install -Dm644 "${srcdir}"/${_realname}-${pkgver}/COPYING.txt \
    "${pkgdir}"${MINGW_PREFIX}/share/licenses/${_realname}/COPYING.txt
}
